import 'babel-polyfill'
import Vue from 'vue'
import VueRouter from 'vue-router'
import VueLazyload from 'vue-lazyload'
import {
    Row,
    Col,
    Card
} from 'element-ui';
//import 'element-ui/lib/theme-chalk/index.css'
//import 'element-ui/lib/theme-chalk/display.css'
import App from './App'
import global from './lib/global'
import axios from 'axios'
import store from './lib/store'

Vue.use(VueRouter)
Vue.use(VueLazyload)
Vue.use(Row)
Vue.use(Col)
Vue.use(Card)

var needHttps = !(location.hostname.endsWith('coupon.etourly.com') || location.hostname == '127.0.0.1' || location.port != '')
if (needHttps && location.protocol == 'http:') {
    location = 'https' + location.toString().substring(4)
} else {
    if (location.hostname.endsWith('etourly.com')) {
        document.title = '旅悠首页'
    }

    location.search.split('?')[1] && location.search.split('?')[1].split('&').forEach(kv => {
        if (kv.split('=')[0] == 'cordova' && kv.split('=')[1] != '0') {
            var head = document.getElementsByTagName('head')[0];
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.src = 'cordova/cordova.js';
            head.appendChild(script);
        }
    })

    //if (document.getElementById('qrcode')) {
    //  new Vue({
    //    el: '#qrcode',
    //    render: h => h(App),
    //    router: new VueRouter({
    //      routes: [{
    //        path: '/',
    //        component(resolve) {
    //          require(['./view/Qrcode'], resolve)
    //        }
    //      }
    //      ]
    //    })
    //  })
    //} else if (document.getElementById('ar')) {
    //  new Vue({
    //    el: '#ar',
    //    render: h => h(App),
    //    router: new VueRouter({
    //      routes: [{
    //        path: '/',
    //        component(resolve) {
    //          require(['./view/AR'], resolve)
    //        }
    //      }
    //      ]
    //    })
    //  })
    //} else
    if (document.getElementById('app')) {
        var routes = []
        if (location.hostname.endsWith('coupon.etourly.com')) {
            routes.push.apply(routes, [{
                path: '/',
                component(resolve) {
                    require(['./view/Coupon'], resolve)
                }
            }])
        } else {
            if (!location.hostname.endsWith('etourly.com')) {
                routes.push.apply(routes, [{
                    path: '/',
                    component(resolve) {
                        require(['./view/Index'], resolve)
                    }
                }, {
                    path: '/add',
                    component(resolve) {
                        require(['./view/Add'], resolve)
                    }
                }, {
                    path: '/login',
                    component(resolve) {
                        require(['./view/Login'], resolve)
                    }
                }, {
                    path: '/page',
                    component(resolve) {
                        require(['./view/Page'], resolve)
                    }
                }, {
                    path: '/edit',
                    component(resolve) {
                        require(['./view/Edit'], resolve)
                    }
                }, {
                    path: '/rss',
                    component(resolve) {
                        require(['./view/Rss'], resolve)
                    }
                }, {
                    //   path: '/takePhoto',
                    //   component(resolve) {
                    //     require(['./view/TakePhoto'], resolve)
                    //   }
                    // }, {
                    //   path: '/recordRTC',
                    //   component(resolve) {
                    //     require(['./view/RecordRTC'], resolve)
                    //   }
                    // }, {
                    //   path: '/viewPhoto',
                    //   component(resolve) {
                    //     require(['./view/ViewPhoto'], resolve)
                    //   }
                    // }, {
                    //   path: '/addTab',
                    //   component(resolve) {
                    //     require(['./view/AddTab'], resolve)
                    //   },
                    //   children: [{
                    //     path: 'shopping',
                    //     component(resolve) {
                    //       require(['./addView/Shopping'], resolve)
                    //     }
                    //   }, {
                    //     path: 'music',
                    //     component(resolve) {
                    //       require(['./addView/Music'], resolve)
                    //     }
                    //   }]
                    // }, {
                    path: '/cache',
                    component(resolve) {
                        require(['./view/Cache'], resolve)
                    }
                }, {
                    path: '/calendar',
                    component(resolve) {
                        require(['./view/Calendar'], resolve)
                    }
                }, {
                    path: '/invite',
                    component(resolve) {
                        require(['./view/Invite'], resolve)
                    }
                }, {
                    path: '/tool',
                    component(resolve) {
                        require(['./view/Tool'], resolve)
                    }
                }, {
                    path: '/redPacket',
                    component(resolve) {
                        require(['./view/RedPacket'], resolve)
                    }
                }, {
                    path: '/texasCalc',
                    component(resolve) {
                        require(['./view/TexasCalc'], resolve)
                    }
                }, ])
            }
            var prefix = location.hostname.endsWith('etourly.com') ? '/' : '/fanli'
            routes.push.apply(routes, [{
                path: prefix,
                component(resolve) {
                    require(['./view/FanLi'], resolve)
                }
            }, {
                path: '/loginTaobao',
                component(resolve) {
                    require(['./view/LoginTaobao'], resolve)
                }
            }, {
                path: '/getTaobaoBill',
                component(resolve) {
                    require(['./view/GetTaobaoBill'], resolve)
                }
            }, {
                path: '/loginJd',
                component(resolve) {
                    require(['./view/LoginJd'], resolve)
                }
            }, {
                path: prefix + 'login',
                component(resolve) {
                    require(['./view/FanLiLogin'], resolve)
                }
            }, {
                path: '/customerMenu',
                component(resolve) {
                    require(['./view/CustomerMenu'], resolve)
                }
            }, {
                path: '/setPassword',
                component(resolve) {
                    require(['./view/SetPassword'], resolve)
                }
            }, {
                path: '/bill',
                component(resolve) {
                    require(['./view/Bill'], resolve)
                }
            }, {
                path: '/bindAlipay',
                component(resolve) {
                    require(['./view/BindAlipay'], resolve)
                }
            }, {
                path: '/returnRecord',
                component(resolve) {
                    require(['./view/ReturnRecord'], resolve)
                }
            }, {
                path: '/adminMenu',
                component(resolve) {
                    require(['./view/AdminMenu'], resolve)
                }
            }, {
                path: '/billData',
                component(resolve) {
                    require(['./view/BillData'], resolve)
                }
            }, {
                path: '/logData',
                component(resolve) {
                    require(['./view/LogData'], resolve)
                }
            }, {
                path: '/customerBill',
                component(resolve) {
                    require(['./view/CustomerBill'], resolve)
                }
            }, {
                path: '/register',
                component(resolve) {
                    require(['./view/Register'], resolve)
                }
            }, {
                path: '/customerLog',
                component(resolve) {
                    require(['./view/CustomerLog'], resolve)
                }
            }, {
                path: '/getJdBill',
                component(resolve) {
                    require(['./view/GetJdBill'], resolve)
                }
            }, {
                path: '/top100',
                component(resolve) {
                    require(['./view/Top100'], resolve)
                }
            }, {
                path: '/coupon',
                component(resolve) {
                    require(['./view/Coupon'], resolve)
                }
            }, {
                path: '/wechatQrcode',
                component(resolve) {
                    require(['./view/WechatQrcode'], resolve)
                }
            }, {
                path: '/promoterList',
                component(resolve) {
                    require(['./view/PromoterList'], resolve)
                }
            }, {
                path: '/promoter',
                component(resolve) {
                    require(['./view/Promoter'], resolve)
                }
            }, {
                path: '/billInfo',
                component(resolve) {
                    require(['./view/BillInfo'], resolve)
                }
            }, {
                path: '/setReturnWay',
                component(resolve) {
                    require(['./view/SetReturnWay'], resolve)
                }
            }, {
                path: '/promotee',
                component(resolve) {
                    require(['./view/Promotee'], resolve)
                }
            }, {
                path: '/activity0',
                component(resolve) {
                    require(['./view/Activity0'], resolve)
                }
            }, {
                path: '/activity0Admin',
                component(resolve) {
                    require(['./view/Activity0Admin'], resolve)
                }
            }, {
                path: '/handleBill',
                component(resolve) {
                    require(['./view/HandleBill'], resolve)
                }
            }, {
                path: '/activityConfig',
                component(resolve) {
                    require(['./view/ActivityConfig'], resolve)
                }
            }, {
                path: '/activityList',
                component(resolve) {
                    require(['./view/ActivityList'], resolve)
                }
            }])
        }
        new Vue({
            el: '#app',
            render: h => h(App),
            router: new VueRouter({
                routes: routes
            }),
        })
    }
}
